package Client;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.table.*;

public class View extends JFrame
{
	private static final long serialVersionUID = 1L;
	private DefaultTableModel model;
	private JPanel panel1, panel2;
	private JButton button1;
	private JTable table;
	private JScrollPane pane;
	private JTextField textField;
	private JLabel label;
	private JTextArea textArea;
	
	
	public View()
	{
		// panel1
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
		setBounds(100, 100, 683, 347);
		getContentPane().setLayout(null);
		
		panel1 = new JPanel();
		panel1.setBounds(0, 0, 257, 279);
		getContentPane().add(panel1);
		panel1.setLayout(null);
		
		label = new JLabel("Enter the name:");
		label.setBounds(10, 27, 184, 14);
		panel1.add(label);
		
		textField = new JTextField();
		textField.setBounds(10, 63, 184, 20);
		panel1.add(textField);
		textField.setColumns(10);
		
		button1 = new JButton("Show the values");
		button1.setBounds(10, 114, 184, 23);
		panel1.add(button1);
		
		textArea = new JTextArea();
		textArea.setBounds(10, 157, 184, 111);
		textArea.setEditable(false);
		panel1.add(textArea);		
		
		// panel2
				
		panel2 = new JPanel();
		panel2.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		String data[][] = {{}};
		String col[] = {"Name", "Value"};
		model = new DefaultTableModel(data, col);
		table = new JTable(model);
		table.setBounds(222, 0, 100, 200);
		JTableHeader header = table.getTableHeader();
		header.setBackground(Color.yellow);
		pane = new JScrollPane(table);
		pane.setBounds(257, 0, 410, 279);
		pane.setColumnHeaderView(panel2);
		getContentPane().add(pane);		
	}
	
	public void addValueListener(ActionListener al)
	{
		button1.addActionListener(al);
	}
	
	public DefaultTableModel getTableModel()
	{
		return model;
	}
	
	public JTable getTable()
	{
		return table;
	}
	
	public String getText()
	{
		return textField.getText();
	}
	
	public void setAreaText(String text)
	{
		textArea.setText(text);
	}
}
